package com.petalsgroup.petals.dao.disInform.impl;

import com.petalsgroup.petals.dao.disInform.DisInformDao;
import com.petalsgroup.petals.pojo.DisInformDO;
import com.petalsgroup.petals.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class DisInformDaoImpl implements DisInformDao {
    private JdbcTemplate template=new JdbcTemplate(JDBCUtils.getDataSource());

    /**
     * 根据ID查询某个用户所有回复的总举报数
     * @param uided
     * @return
     * @author wgd
     */
    @Override
    public Long getDisInformNunByUided(Integer uided) {
        String sql="select count(*) from dis_inform where uided = ?";
        Long disCount = template.queryForObject(sql, long.class, uided);
        return disCount;
    }

    /**
     * 根据ID删除某个用户所有回复的举报记录
     * @param uided
     * @author wgd
     */
    @Override
    public void deleteDisInformByUided(Integer uided) {
        String sql="delete from dis_inform where uided = ?";
        template.update(sql,uided);
    }

    /**
     * 判断用户是不是已经举报过这条回复
     * @param uid
     * @param dis_id
     * @return
     */
    @Override
    public Boolean disInformAgain(Integer dis_id,Integer uid) {
        String sql="select * from dis_inform where uid = ? and did = ? ";
        List<DisInformDO> list = template.query(sql, new BeanPropertyRowMapper<>(DisInformDO.class), uid, dis_id);
        return list.size()>0 ? true : false;
    }

    @Override
    public void addDisInform(String dis_id, String uid, String uided, String iid) {
        String sql = "insert into dis_inform values(null,?,?,?,?)";
        template.update(sql,dis_id,uid,uided,iid);
    }
}
